﻿var BF= (function (bf) {
    bf.init = function () {};
    return bf;
})(BF || {});

//计算请假天数
BF.HRGetEmpTotalVation = (function (emptotalvation) {
    //debugger
    var _baseAPIUrl = "BpmLibraryManager.aspx/HRGetEmpTotalVation"; //?r="+Math.random()+"
    var _currentParams = [];
    var _loaded = false;

    var _EmployeeID = '';
    var _FrmDatetime = '';
    var _TODatetime = '';
    var _IsIncludeHoliday = '';

    var _LeaveDay = '';
    var _LeaveTime = '';
    var _Msg = '';

    //string EmployeeID, string FrmDatetime, string TODatetime, string IsIncludeHoliday
    emptotalvation.init = function (xEmployeeID, xFrmDatetime, xTODatetime, xIsIncludeHoliday) {
        _EmployeeID = xEmployeeID;
        _FrmDatetime = xFrmDatetime;
        _TODatetime = xTODatetime;
        _IsIncludeHoliday = xIsIncludeHoliday;
        BF.HRGetEmpTotalVation.open();
    };

    emptotalvation.open = function () {
        if (!_loaded) {
            _load();
            _loaded = false;
        }
    };
    function _load(append) {
        _currentParams = {
            EmployeeID: _EmployeeID,
            FrmDatetime: _FrmDatetime,
            TODatetime: _TODatetime,
            IsIncludeHoliday: _IsIncludeHoliday
        };
        var callback = append === true ?
        function (data) {
            _populate(data, true)
        } : _populate;

        Query.execute(_baseAPIUrl, _currentParams, callback)
    }
   function _populate(data, append) {
        if (data) {
            if (data.indexOf('ERR%') >= 0) {
                var dataArray = data.split("@");
                alert("计算请假天数失败" + dataArray[1]);
            } else {
                if (data.indexOf('OK%') >= 0) {
                    var respArray = data.split("@");
                    if (respArray[0] == "OK%") {
                        var totalArray = respArray[1].split("|");
                        _LeaveDay = totalArray[0];
                        _LeaveTime = totalArray[1];
                        _Msg = totalArray[2];
                    }
                }
            }
        }
    };

    //天数
    emptotalvation.getLeaveDay = function () {
        return _LeaveDay;
    };
    //小时数
    emptotalvation.getLeaveTime = function () {
        return _LeaveTime;
    };
    //消息
    emptotalvation.getMsg = function () {
        return _Msg;
    };
    return emptotalvation
})(BF.HRGetEmpTotalVation || {});



//获取指定员工的打卡记录。
BF.EmpwkCardData = (function (empwkcard) {

    var _baseAPIUrl = "BpmLibraryManager.aspx/EmpwkCardData";
    var _currentParams = [];
    var _loaded = false;

    var _EmployeeID = '';
    var _CardDate = '';
    var _MinCardTime = '';
    var _MaxCardTime = ''

    //string EmployeeID, string CardDate
    empwkcard.init = function (xEmployeeID, xCardDate) {

        _EmployeeID = xEmployeeID;
        _CardDate = xCardDate;
        BF.EmpwkCardData.open();
    };

    empwkcard.open = function () {
        if (!_loaded) {
            _load();
            _loaded = true;
        }
    };
    function _load(append) {
        _currentParams = {
            EmployeeID: _EmployeeID,
            CardDate: _CardDate
        };
        var callback = append === true ?
        function (data) {
            _populate(data, true)
        } : _populate;

        Query.execute(_baseAPIUrl, _currentParams, callback)
    }
    function _populate(data, append) {
        if (data) {
            if (data.indexOf('ERR%') >= 0) {
                var dataArray = data.split("@");
                alert("获取指定员工的打卡记录失败" + dataArray[1]);
            } else {
                if (data.indexOf('OK%') >= 0) {
                    var respArray = data.split("@");
                    if (respArray[0] == "OK%") {
                        var totalArray = respArray[1].split("|");
                        _MinCardTime = totalArray[0];
                        _MaxCardTime = totalArray[1];
                    }
                }
            }
        }
    };

    //打卡日期
    empwkcard.getCardDate = function () {
        return _CardDate;
    };
    //上班时间
    empwkcard.getMinCardTime = function () {
        return _MinCardTime;
    };
    //下班时间
    empwkcard.getMaxCardTime = function () {
        return _MaxCardTime;
    };
    return empwkcard
})(BF.EmpwkCardData || {});


BF.PostRankName = (function (postrank) {

    var _baseAPIUrl = "BpmLibraryManager.aspx/GetPostRankName";
    var _currentParams = [];
    var _loaded = false;

    var _PostID = '';
    var _PostRankName = '';

    postrank.init = function (xPostID) {

        _PostID = xPostID;
        BF.PostRankName.open();
    };

    postrank.open = function () {

        _load();
        // _loaded = false;

    };
    function _load(append) {
        _currentParams = {
            PostID: _PostID
        };
        var callback = append === true ?
        function (data) {
            _populate(data, true)
        } : _populate;

        Query.execute(_baseAPIUrl, _currentParams, callback)
    }
    function _populate(data, append) {
        if (data) {
            if (data.indexOf('ERR%') >= 0) {
                var dataArray = data.split("@");
                alert("获取指定岗位名获得职级名称失败" + dataArray[1]);
            } else {
                if (data.indexOf('OK%') >= 0) {
                    var respArray = data.split("@");
                    if (respArray[0] == "OK%") {
                        var totalArray = respArray[1].split("|");
                        _PostRankName = totalArray[0];
                    }
                }
            }
        }
    };

    //获得职级名称
    postrank.getPostRankName = function () {
        return _PostRankName;
    };
    return postrank
})(BF.PostRankName || {});

//公开课费用明细记录
BF.GetSubjectList = (function (subject) {

    var _baseAPIUrl = "BpmLibraryManager.aspx/GetSubjectList";
    var _currentParams = [];
    var _loaded = false;

    var _SubjectList = null;

    subject.init = function () {
       
        BF.GetSubjectList.open();
    };

    subject.open = function () {

        _load();
        _loaded = false;

    };
    function _load(append) {
        _currentParams = {};
        var callback = append === true ?
        function (data) {
            _populate(data, true)
        } : _populate;

        Query.execute(_baseAPIUrl, _currentParams, callback)
    }
    function _populate(data, append) {
        if (data) {
            if (data.indexOf('ERR%') >= 0) {
                var dataArray = data.split("@");
                alert("获取公开课费用明细记录数据失败" + dataArray[1]);
            } else {
                var person = JSON.parse(data);

                if (person) {
                    _SubjectList = person;
                }

            }
        }
    };


    subject.getSubjectList = function () {
        return _SubjectList;
    };

    return subject
})(BF.GetSubjectList || {});



